
#include "waitqueue.h"


waitqueue_t active_list;

waitqueue_t 
*wq_init(waitqueue_t *wq)
{
    list_init(&wq->process_list);
    return wq;
}

waitqueue_t 
*wq_push(waitqueue_t *wq, process_t *process)
{
    list_push(&wq->process_list, &process->process_node);
    return wq;
}

waitqueue_t 
*wq_enqueue(waitqueue_t *wq, process_t *process)
{
    list_append(&wq->process_list, &process->process_node);
    return wq;
}

process_t 
*wq_pop(waitqueue_t *wq)
{
    list *node = NULL;
    node = list_pop(&wq->process_list);
    if (node)
      return ((process_t *)node);
    else
      return NULL;
}

process_t 
*wq_peek(waitqueue_t *wq)
{
    list *node;
    node = list_first(&wq->process_list);
    if (node)
      return ((process_t *)node);
    else
      return NULL;
}

waitqueue_t 
*wq_enqueue_all(waitqueue_t *dest, waitqueue_t *src)
{
    list_concat( &dest->process_list, &src->process_list );
    return dest;
}

void 
wq_dequeue(process_t *process)
{
    (void)list_remove( &process->process_node );
}

